﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _2_13
{
    public partial class Form1 : Form
    {
        string specialChar = "~!@#$%^&*()_+|{}<>?`-=\\[]';:,./";
        public Form1()
        {
            InitializeComponent();
        }
        private int CheckPass(string pass)
        {
            // 验证长度（至少8位）
            if (pass.Length < 8) return 0;

            int[] cType = new int[4]; // 0:数字、1:大写、2:小写、3:特殊字符
            foreach (char c in pass)
            {
                if (Char.IsNumber(c)) cType[0] = 1;
                else if (Char.IsUpper(c)) cType[1] = 1;
                else if (Char.IsLower(c)) cType[2] = 1;
                else if (specialChar.Contains(c)) cType[3] = 1;
                else return 0; // 含非法字符
            }

            // 统计字符类型数量
            return cType.Sum(); // 返回1-4
        }
        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            string pass = textBox1.Text;
            int typeCount = CheckPass(pass);
            switch (typeCount)
            {
                case 0:
                    MessageBox.Show("密码不得小于8位！且只能是字母、数字和指定特殊字符的组合！");
                    label3.Text = "";
                    break;
                case 1:
                    label3.Text = "弱";
                    label3.BackColor = Color.Red;
                    break;
                case 2:
                    label3.Text = "较弱";
                    label3.BackColor = Color.Orange;
                    break;
                case 3:
                    label3.Text = "较强";
                    label3.BackColor = Color.Yellow;
                    break;
                case 4:
                    label3.Text = "强";
                    label3.BackColor = Color.Green;
                    break;
            }
        }
    }
}

